package com.study.compose.beta.view

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.module.compose.base.composable.CodeView
import com.study.compose.beta.R

@OptIn(
    ExperimentalAnimationApi::class
)
@Composable
fun VisibilitySample() {
    var expand by remember {
        mutableStateOf(true)
    }

    LazyColumn(
        Modifier
            .fillMaxSize()
            .padding(start = 15.dp, end = 15.dp)
    ) {
        item {
            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .fillMaxHeight()
            ) {
                Card(
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(30.dp)
                ) {
                    Column(
                        modifier = Modifier
                            .padding(30.dp)
                            .clickable { expand = !expand },
                        horizontalAlignment = Alignment.CenterHorizontally,
                        verticalArrangement = Arrangement.Center
                    ) {
                        Image(
                            painter = painterResource(id = R.mipmap.icon_android),
                            contentDescription = "图标"
                        )
                        AnimatedVisibility(
                            visible = expand
                        ) {
                            Text(
                                modifier = Modifier.padding(top = 20.dp),
                                text = "Hello Compose",
                                style = MaterialTheme.typography.h5
                            )
                        }
                    }
                }

                CodeView(
                    code =
                    """
                    AnimatedVisibility(visible = expand) {
                        Text(
                            modifier = Modifier.padding(top = 20.dp),
                            text = "Hello Compose",
                            style = MaterialTheme.typography.h5
                        )
                    }
                    """.trimIndent()
                )
            }
        }
    }
}